from Pinyin2Hanzi import DefaultHmmParams, viterbi, simplify_pinyin
from pyfgl import *
hmmparams = DefaultHmmParams()
pinyin="nishishui"
def convert(pinyin, num):
    global hmmparams
    pinyin=crcpinyin(pinyin)
    pinyinl=[list(i) for i in pinyin]
    for i,j in enumerate(pinyinl):
        for k,l in enumerate(j):
            pinyinl[i][k]=simplify_pinyin(l)
    rst=[]
    for p in pinyinl:
        try:
            result = viterbi(hmmparams,p,path_num=num)
            rst+=result
        except KeyError:
            pass
    rst.sort(key=lambda i:i.score,reverse=True)
    for i,j in enumerate(rst):
        rst[i]=''.join(j.path)
    return rst[:num]
for i in convert(pinyin,10):
    print(i)
